package com.hhq.sso.system.entity;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.springblade.core.tool.node.INode;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 实体类
 *
 * @author Chill
 * @since 2018-12-24
 */
@Data
@TableName("blade_dict")
@Schema(description = "Dict对象")
public class Dict implements Serializable, INode<Dict> {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Schema(description = "主键")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /**
     * 父主键
     */
    @Schema(description = "父主键")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;

    /**
     * 字典码
     */
    @Schema(description = "字典码")
    private String code;

    /**
     * 字典值
     */
    @Schema(description = "字典值")
    private Integer dictKey;

    /**
     * 字典名称
     */
    @Schema(description = "字典名称")
    private String dictValue;

    /**
     * 排序
     */
    @Schema(description = "排序")
    private Integer sort;

    /**
     * 字典备注
     */
    @Schema(description = "字典备注")
    private String remark;

    /**
     * 是否已删除
     */
    @TableLogic
    @Schema(description = "是否已删除")
    private Integer isDeleted;

    /**
     * 子孙节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    @TableField(exist = false)
    private List<Dict> children;

    @Override
    public List<Dict> getChildren() {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        return this.children;
    }
}
